package com.zy.springbootmybatis.controller.test1;

import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.util.List;

public class WordReader {
    public static void main(String[] args) {
        try {
            FileInputStream fis = new FileInputStream(new File("D:\\aa.docx"));
            XWPFDocument document = new XWPFDocument(fis);

            // 读取段落
            List<XWPFParagraph> paragraphs = document.getParagraphs();
            for (XWPFParagraph para : paragraphs) {
               // System.out.println(para.getText());
                try {
                    FileWriter pw = new FileWriter("D://1.txt", true);
                    pw.write(para.getText());
                    pw.flush();
                    pw.close();
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }

            fis.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}